package net.lahuobao.finance.service.impl.household;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import net.lahuobao.finance.entity.account.AccountEntity;
import net.lahuobao.finance.entity.account.EAccountType;
import net.lahuobao.finance.entity.household.HouseholdEntity;
import net.lahuobao.finance.entity.organizationEntity.OrganizationEntity;
import net.lahuobao.finance.service.household.HouseholdServiceI;

import java.math.BigDecimal;
import java.text.SimpleDateFormat;
import java.util.Date;

import org.jeecgframework.core.common.service.impl.CommonServiceImpl;
import org.jeecgframework.core.util.ResourceUtil;

@Service("householdService")
@Transactional
public class HouseholdServiceImpl extends CommonServiceImpl implements HouseholdServiceI {
	
	public void saveHousehold(HouseholdEntity household)throws Exception{
		save(household);
		OrganizationEntity organ = new OrganizationEntity();
		organ.setValidateState(2);//已验证
		organ.setShowPhoneOwner("1");
		organ.setOrganizationName(household.getName());
		save(organ);
		long organization_id = organ.getOrganizationId();
		AccountEntity account = new AccountEntity();
		account.setFrozen(BigDecimal.ZERO);
		account.setUsable(BigDecimal.ZERO);
		account.setTotal(BigDecimal.ZERO);
		account.setAccountType(EAccountType.OrganizationMember.getValue());
		account.setOrganizationId(organization_id);
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd Hh:mm:ss");
		Date oprateTime = sdf.parse(sdf.format(new Date()));
		account.setOperateTime(oprateTime);
		account.setOperateId(0);
		account.setBankAccountName("个体户账户");
		account.setAboutId(household.getId());
		save(account);
	}
}